package com.chinapay.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chinapay.config.BankpayConfig;

/**
 * @author zqh
 * @date 2014年10月13日
 * 
 */
@Component
public class CreatePayHtml {
	@Autowired
	private static BankpayConfig bankpayConfig;
	 public static String buildRequest(Map<String, String> sParaTemp) {
	        List<String> keys = new ArrayList<String>(sParaTemp.keySet());
	        StringBuilder sbHtml = new StringBuilder();
	        
	        sbHtml.append("<form name=\"chinapaySubmit\" action=\"").append(bankpayConfig.gateUrl).append("\" method=\"post\">");
	        for (int i = 0; i < keys.size(); i++) {
	            String name = keys.get(i);
	            String value = sParaTemp.get(name);
	            sbHtml.append("<input type=\"hidden\" name=\"").append(name).append("\" value=\"").append(value).append("\"/>");
	        }
	        sbHtml.append("</form>");
	        sbHtml.append("<script>document.forms['chinapaySubmit'].submit();</script>");
	        String html = sbHtml.toString();
	        return html;
	    }
}
